import 'package:app/common/tool.dart';
import 'package:app/pages/daily_work_report_module/my_daily_detail_module/my_daily_detail_view.dart';
import 'package:app/pages/daily_work_report_module/my_daily_module/my_daily_controller.dart';
import 'package:app/pages/published_daily_module/published_daily_view.dart';
import 'package:app/router/app_pages.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';


import '../../../common/app_theme.dart';
import '../../../common/colors.dart';
import '../../../components/base_scaffold_appbar.dart';
import '../../../components/nodata_page.dart';
import '../top_dialog_page.dart';
import '../../../services/address.dart';
import '../../../utils/search_module.dart';
import 'my_daily_model.dart';
import 'package:cached_network_image/cached_network_image.dart';


class MyDailyView extends GetView{


  MyDailyController controller = Get.put(MyDailyController());


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      floatingActionButton: GestureDetector(
        child: Container(
          width: 40,
          height: 40,
          decoration: BoxDecoration(
            color: AppColor.themeColor,
            borderRadius: BorderRadius.all(Radius.circular(20)),
          ),
          alignment: Alignment.center,
          child: Text(
            '+',
            style: TextStyle(fontSize: 25, color: Colors.white),
          ),
        ),
        onTap: () async {
         var data = await Get.toNamed(AppRoutes.publishedDaily);
         if(data == 'refresh'){
           controller.requestData();
         }
          // var data = await Get.to(PubLishedDailyView());
          // if (data == 'refresh') {
          //   requestData();
          // }
        },
      ),
      appBar:BaseAppBar(preferredSize: Size(Get.width,AppTool.appBarHEIGHT),
      child: Text('我的日报'),),
      // AppBar(
      //   leading: IconButton(
      //     onPressed: () {
      //       Get.back();
      //     },
      //     icon: Image.asset(
      //       'images/leftarr.png',
      //       color: Colors.white,
      //       width: 15,
      //       height: 15,
      //     ),
      //   ),
      //   title: Text('我的日报'),
      //   backgroundColor: AppColor.themeColor,
      // ),
      body: Container(
        child: GetBuilder<MyDailyController>(builder: (_){
          return Column(
            children: [
              Container(
                color: Colors.white,
                height: 35,
                child: Row(
                  children: [
                    Container(
                      margin: EdgeInsets.only(left: 15),
                      child: Row(
                        children: [
                          GestureDetector(
                            child: Text(
                              controller.replyType,
                              style: appThemeData.textTheme.bodyText1!
                                  .copyWith(fontSize: 13),
                            ),
                            onTap: () =>controller.topClick(),
                          ),
                          controller.isTopShow == false
                              ? Image.asset(
                            'images/arrow-down.png',
                            width: 12,
                            height: 12,
                          )
                              : Image.asset(
                            'images/arrow-up.png',
                            width: 12,
                            height: 12,
                            color: AppColor.themeColor,
                          )
                        ],
                      ),
                    ),
                    Container(
                        decoration: BoxDecoration(
                            color: AppColor.bgColor,
                            borderRadius: BorderRadius.all(Radius.circular(13))),
                        width: Get.width - 120,
                        alignment: Alignment.centerLeft,
                        margin: EdgeInsets.only(top: 0, left: 10, right: 10),
                        padding: EdgeInsets.only(left: 15),
                        height: 25,
                        child: Row(
                          children: [
                            Icon(
                              Icons.search,
                              size: 20,
                              color: AppColor.smallTextColor,
                            ),
                            Container(
                              alignment: Alignment.center,
                              color: Colors.transparent,
                              width: Get.width - 170,
                              height: 30,
                              child: TextField(
                                controller: controller.editingController,
                                onChanged: (values) {
                                  controller.requestData(search: values);
                                },
                                decoration: InputDecoration(
                                    isCollapsed: true,
                                    border: InputBorder.none,
                                    hintText: '请输入关键词',
                                    hintStyle: TextStyle(
                                        color: AppColor.hintColor, fontSize: 13)),
                                style: TextStyle(
                                    color: AppColor.smallTextColor, fontSize: 14),
                              ),
                            )
                          ],
                        )),
                  ],
                ),
              ),
              Expanded(
                  child: Container(
                    padding: EdgeInsets.only(top: 5),
                    color: AppColor.bgColor,
                    width: Get.width,
                    child: GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                        /// 页面点击响应
                        SearchModule.closeKeyboard(context);
                      },
                      onPanDown: (_) {
                        /// 列表滑动响应
                        SearchModule.closeKeyboard(context);
                      },
                      child:
                      EasyRefresh.custom(
                        controller: controller.easyRefreshController,
                        // emptyWidget: Container(
                        //   child: Text('暂无数据'),
                        // ),
                        header: MaterialHeader(),
                        footer: MaterialFooter(),
                        emptyWidget: controller.dataArr.isNotEmpty
                            ? null
                            : Container(
                          height: Get.height,
                          color: Colors.red,
                          child: NoDataPage(),
                        ),
                        onRefresh: () =>controller.pullToData(),
                        onLoad: () => controller.onLoadToData(),
                        slivers: [
                          SliverList(
                            delegate: _mySliverChildBuilderDelegate(),
                          ),
                        ],
                      ),
                    ),
                  )),
            ],
          );
        }),
      ),


    );
  }

  _mySliverChildBuilderDelegate() {
    return SliverChildBuilderDelegate(
          (BuildContext context, int index) {
        MyDailyItemModel _model = controller.dataArr[index];
        return GestureDetector(
          onTap: () {
            controller.pushToView(index);
            // Get.to(MyDailyDetailPage(_model.id));

            // Get.to(MyDailyDetailView(),arguments: _model.id);
            // print('_model.id ===========${_model.id}');
          },
          child: Container(
            // margin: EdgeInsets.all(5),
            // height: 10,
            margin: EdgeInsets.only(top: 5),
            padding: EdgeInsets.only(left: 15),
            color: Colors.white,
            child: Row(
              children: [
                // CachedNetworkImage(
                //   width: 50,
                //   height: 50,
                //   imageUrl: "${Address.homeHost}${_model.headerImg}",
                //   placeholder: (context, url) => CircularProgressIndicator(),
                //   errorWidget: (context, url, error) => Icon(Icons.error),
                // ),
                CircleAvatar(
                  radius: 20,
                  backgroundImage: NetworkImage(
                    '${Address.homeHost}${_model.headerImg}'
                  ),
                  // child: Image.network('${Address.homeHost}${_model.headerImg}',fit: BoxFit.fill,),
                ),
                Container(
                  margin: EdgeInsets.only(
                    left: 5,
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        margin: EdgeInsets.only(top: 10),
                        color: Colors.white,
                        width: Get.width - 80,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '${_model.author}',
                              style: appThemeData.textTheme.bodyText1,
                            ),
                            Text(
                              '${_model.createDate}',
                              style: appThemeData.textTheme.bodyText1!.copyWith(
                                  color: AppColor.themeColor, fontSize: 10),
                            )
                          ],
                        ),
                      ),
                      SizedBox(
                        height: 3,
                      ),
                      Text(
                        '${_model.teamName}',
                        style: appThemeData.textTheme.subtitle1
                            ?.copyWith(fontSize: 11),
                      ),
                      SizedBox(
                        height: 3,
                      ),
                      Container(
                          width: Get.width - 80,
                          // color: Colors.lightGreen,
                          margin: EdgeInsets.only(top: 5),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text(
                                '${_model.dateBeauty}',
                                style: appThemeData.textTheme.subtitle1
                                    ?.copyWith(fontSize: 11),
                              ),
                              Row(
                                children: [
                                  GestureDetector(
                                    onTap: () {},
                                    child: Image.asset(
                                      'images/comment_icon.png',
                                      width: 14,
                                      height: 14,
                                      color: AppColor.smallTextColor,
                                    ),
                                  ),
                                  SizedBox(
                                    width: 5,
                                  ),
                                  GestureDetector(
                                    onTap: () {},
                                    child: Image.asset(
                                      'images/like_icon.png',
                                      width: 14,
                                      height: 14,
                                      color: AppColor.smallTextColor,
                                    ),
                                  ),
                                ],
                              )
                            ],
                          )),
                      SizedBox(
                        height: 3,
                      ),
                    ],
                  ),
                )
              ],
            ),
          ),
        );
      },
      childCount: controller.dataArr.length,
    );
  }
}